#ifndef __IPMS_CLIENT_API_H
#define __IPMS_CLIENT_API_H

#include <dicom/list.h>
#include <dicom/string_ext.h>

typedef struct {
   int ID;                 /* PCD ID */
   char MAC[24];            /* PCD MAC */
   char Description[128];  /* Description for PCD (ex: TV@living room) */
   struct list_head node;  /* Used for PCDList */
} PCDInfo_t;

typedef struct {
   int Voltage;          /* Voltage */
   int Current;          /* Current */
   int InstantPower;    /* Instantaneous power */
   int AccumPower;      /* Accumulated power */
   char Datetime[20];    /* Date and time of received report data */
} PCDReportData_t;

typedef struct {
   int TimeLeft;     /* Time left to change state (Unit: 100ms) */
   int Status;       /* Bit1: Next state, Bit0: Current state */
} PCDStatus_t;

/*
 * Status Bits:
 *   Bit1  Bit0  |  Status
 *   -------------------------------
 *    0     0    |  OFF (No status change)
 *    0     1    |  ON ->OFF (After TimeLeft expired)
 *    1     0    |  OFF -> ON (After TimeLeft expired)
 *    1     1    |  ON (No status change)
 */

#define API_REPORT_SEL_VOLT        0x01
#define API_REPORT_SEL_CURR        0x02
#define API_REPORT_SEL_INST_ENERG  0x04
#define API_REPORT_SEL_ACCUM_ENERG 0x08
#define API_REPORT_SEL_ALL         0x0F

#define API_EVENT_STAT_CHANGE      0x01
#define API_EVENT_AUTO_REPORT      0x02

#define API_CTRL_TYPE_ONOFF        0x01
# define CTRL_ON  1
# define CTRL_OFF 0


#define API_ERR_INVAL_ARG          -1     /* Invalid arguments */
#define API_ERR_BAD_SOCKET         -2     /* Failed on creating socket for connection */
#define API_ERR_BAD_CONN           -3     /* Failed on connecting to server */
#define API_ERR_NO_DEVICE          -4     /* Specified device not found */
#define API_ERR_BAD_ID             -5     /* Unknown PCD ID */
#define API_ERR_BAD_MAC            -6     /* Unknown PCD MAC */
#define API_ERR_INVAL_TIME         -7     /* Invalid date time */
#define API_ERR_INVAL_EVENT        -8     /* Invalid event type */


int IPMS_InitAPI(void);
int IPMS_Release(void);
int IPMS_Connect(char *IP, int Port);
int IPMS_Disconnect(int ConnID);
PCDInfo_t *IPMS_PCDRegister(char *MAC, char *Desc);
int IPMS_PCDUnregister(int ID);
int IPMS_PCDGetList(PCDInfo_t *List[], int *Count);
char *IPMS_PCDGetMAC(int ID);
int IPMS_PCDGetID(char *MAC);
PCDReportData_t *IPMS_PCDGetReport(int ID);
int IPMS_PCDGetVoltage(int ID);
int IPMS_PCDGetCurrent(int ID);
int IPMS_PCDGetInstantPower(int ID);
int IPMS_PCDGetAccumPower(int ID);
int IPMS_AutoReportStart(int ID, unsigned int Time, int Selection);
int IPMS_AutoReportStop(int ID);
int IPMS_PCDControl(int ID, unsigned int Type, unsigned int Ctrl, unsigned short Time);
int IPMS_InstallEventHandler(int EventType, void *handler);


#endif
